﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Site.Master" AutoEventWireup="true" CodeBehind="SlideEdit.aspx.cs" Inherits="VK.Casemeet.Web.Admin.Slides.SlideEdit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentHead" runat="server">
    <script type="text/javascript" src="/Scripts/ajaxupload.js"></script>
    <script type="text/javascript">
    function PhotoEntity(photoID, objectID, objectType, imgUrl, name, jumpUrl, target) {
        this.PhotoID = photoID;
        this.ObjectID = objectID;
        this.ObjectType = objectType
        this.ImgUrl = imgUrl;
        this.Created = '';
        this.Name = name;
        this.JumpUrl = jumpUrl;
        this.Target = target;
    }

    function butMoveUp(sender) {
        var onthis = $(sender).parent().parent();
        var getup = $(sender).parent().parent().prev();
        $(getup).before(onthis);
    }

    function butMoveDown(sender) {
        var onthis = $(sender).parent().parent();
        var getdown = $(sender).parent().parent().next();
        $(getdown).after(onthis);
    }

    function butsubmit() {
        if (validator.form()) {
            //图片
            var imgUrlArray = new Array();
            $("#imgArea .slideItme").each(function (i) {
                imgUrlArray[i] = new PhotoEntity(0, 0, 0,
                    $(this).find("img").attr("src").replace('/UserImages/Photos/', ''),
                    '',
                    $(this).find("[type=text]").val(),
                    $(this).find("select").val());
            });
            //alert(JSON.stringify(imgUrlArray));
            $("#hidImgUrlArray").val(JSON.stringify(imgUrlArray));
            return true;
        } else {
            return false;
        }
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
    <div class="bodyContent divBody">
        <div class="divDetailOper">
            <asp:LinkButton ID="butSave" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return butsubmit()">保存信息</asp:LinkButton>
            <a class="butBack" href="SlideList.aspx">返回列表</a>
        </div>
        <div class="left" style="width:98%;margin:10px 0 0 1%;_margin:10px 0 0 0.5%;height:auto;">
            <div class="divEdit" style="width:100%;">
                <div class="title">基本信息</div>
                <div class="content">
                    <table cellpadding="0" cellspacing="0" class="tableLeftEdit">
                    <tbody>
                        <tr>
                            <th>说明：</th>
                            <td><asp:Label ID="lbExplain" runat="server" Text=""></asp:Label></td>
                        </tr>
                        <tr>
                            <th>宽(px)：</th>
                            <td><asp:Label ID="lbWidth" runat="server" Text=""></asp:Label></td>
                        </tr>
                        <tr>
                            <th>高(px)：</th>
                            <td><asp:Label ID="lbHeight" runat="server" Text=""></asp:Label></td>
                        </tr>
                    </tbody>
                    </table>
                </div>
            </div>
            <div class="divEdit martop10" style="width:100%;padding-bottom:20px;">
                <div class="title">
                    <p class="contenta">相册图片</p>
                    <p class="contentb"><span class="padlef20" style="color:Red;"></span><a href="#" id="butImgUrl" style="color:#1d3d83;">【点我上传图片】</a></p>
                    <input id="hidImgUrlArray" name="hidImgUrlArray" type="hidden" value='<% =imgUrl %>' />
                    <script type="text/javascript">
                        $(document).ready(function () {
                            var button = $('#butImgUrl'), interval;
                            new AjaxUpload(button, {
                                action: '',
                                onSubmit: function (file, ext) {
                                    if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                                        alert('错误:图片格式不正确!');
                                        return false;
                                    }
                                    if ($("#imgArea").children("div").length >= 10) {
                                        alert('图片上传限制10张');
                                        return false;
                                    }
                                    this._settings.action = '/PageHandler/UpLoadFile.ashx?folderName=Photos/';
                                    this._settings.data = { oldFileName: $('#divImgUrl img').attr('src') };
                                    this.disable();
                                    var tips = $("#butImgUrl").prev();
                                    tips.html("文件上传中请等待");
                                    interval = window.setInterval(function () {
                                        if (tips.html().length < 20) {
                                            tips.html(tips.html() + ">");
                                        } else {
                                            tips.html('文件上传中请等待');
                                        }
                                    }, 300);
                                },
                                onComplete: function (file, response) {
                                    $("#butImgUrl").prev().html('');
                                    window.clearInterval(interval);
                                    this.enable();
                                    window.clearInterval(interval);
                                    var jsondata = JSON.parse(response);
                                    if (jsondata.Error.length == 0) {
                                        $("#imgArea").append("<div class='slideItme' style='float:left;width:145px;height:160px;border:1px solid #eaeaea;background:#f5f5f5;margin:10px 0 0 10px;padding:0 0 5px 0px'>" +
                                            "   <img alt='' src='/UserImages/Photos/" + jsondata.FileName + "' style='width:139px;height:100px;padding:3px;'/>" +
                                            "   <input type='text' placeholder='填写跳转网址' style='width:128px;' class='martop5' /><br /> " +
                                            "   <div class='left padtop5 padlef5'><select><option value='1'>页内跳转</option><option value='2' selected>新建窗口</option></select></div> " +
                                            "   <div class='left padtop5 padlef10'><p class='sj10 hg22 txtlef hand sj10' onclick='$(this).parent().remove()'>删除</p></div> " +
                                            "</div>");
                                    } else {
                                        alert(jsondata.Error);
                                    }
                                }
                            });
                        });
                    </script>
                </div>
                <div id="imgArea" class="content">
                    <asp:Repeater ID="rptPhoto" runat="server">
                    <ItemTemplate>
                        <div class='slideItme' style='float:left;width:145px;height:180px;border:1px solid #eaeaea;background:#f5f5f5;margin:10px 0 0 10px;padding:0 0 5px 0px'>
                            <img alt='' src='/UserImages/Photos/<%# Eval("ImgUrl") %>' style='width:139px;height:100px;padding:3px;'/>
                            <input type='text' placeholder='填写跳转网址' style='width:130px;' class='inputText padtop5' value='<%# Eval("JumpUrl") %>' />
                            <div class='padtop5 padlef5'><select class='selectddl'><option value='1' <%# ((int)Eval("Target"))==1?"selected":"" %>>页内跳转</option><option value='2' <%# ((int)Eval("Target"))==2?"selected":"" %>>新建窗口</option></select></div>
                            <div class='padtop5 padlef5'>
                                <span class='sj10 hg22 txtlef hand sj10' onclick='butMoveUp(this)'>上移</span>
                                <span class='sj10 hg22 txtlef hand sj10' onclick='butMoveDown(this)'>下移</span>
                                <span class='sj10 hg22 txtlef hand sj10' onclick='$(this).parent().parent().remove()'>删除</span>
                            </div>
                        </div>
                    </ItemTemplate>
                    </asp:Repeater>
                </div>
            </div>
        </div>
        <div class="clear f0" style="height:10px; width:100%"></div>
        <div class="clear divDetailOper">
            <asp:LinkButton ID="LinkButton1" runat="server" CssClass="butSave" onclick="butSave_Click" OnClientClick="return butsubmit()">保存信息</asp:LinkButton>
            <a class="butBack" href="SlideList.aspx">返回列表</a>
        </div>
        <div class="clear f0" style="height:20px; width:100%"></div>
    </div>
</asp:Content>
